﻿<script src="~/vue/dist/vue.global.js"></script>
<link href="~/element-plus/dist/index.css" rel="stylesheet" />
<script src="~/element-plus/dist/index.full.js"></script>
<script src="~/axios/dist/axios.js"></script>
<div id="app">
    <table width="100%">
        <tbody>
            <tr>
                <td style="background-color:#ffffcc">
                    <font color="black">
                        您正在做的业务是：人力资源--客户化设置--人力资源档案管理设置--II级机构设置
                    </font>
                </td>
            </tr>
            <tr>
                <td align="right" style="background-color:#ffffcc">
                    <el-button v-on:click="add()">添加</el-button>
            </tr>
        </tbody>
    </table>
    <el-table :data="tableData" style="width: 100%;background-color: #ffffbb;" :row-class-name="tableRowClassName">
        <el-table-column prop="firstKindName" label="I级机构名称"></el-table-column>
        <el-table-column prop="secondKindId" label="II级机构编号"></el-table-column>
        <el-table-column prop="secondKindName" label="II级机构名称"></el-table-column>
        <el-table-column prop="secondSalaryId" label="薪酬发放责任人编号"></el-table-column>
        <el-table-column prop="secondSaleId" label="销售责任人编号"></el-table-column>
        <el-table-column label="变更">
            <template #default="scope">
                <el-button size="small" v-on:click="handleEdit(scope.row.fskId)">
                    变更
                </el-button>
            </template>
        </el-table-column> 
        <el-table-column label="删除数据">
            <template #default="scope">
                <el-button size="small"
                           type="danger"
                           v-on:click="handleDelete(scope.row.fskId)">
                    删除
                </el-button>
            </template>
        </el-table-column>
    </el-table>

    <div id="pageDiv">
        <span class="span1">  总数：{{pageCount}} 例    当前第{{pageIndex}}页 /每页显示 {{pageSize}} 条    共 {{page}} 页  </span>
        <div class="div">
            <button v-on:click="HomePage()">首页</button>
            <button v-on:click="PreviousPage()">上一页</button>
            <button v-on:click="NextPage()">下一页</button>
            <button v-on:click="LastPage()">尾页</button>
            跳到第
            <input type="text" style="width: 30px;height: 20px;" v-model="pages">
            <a>页</a>
            <button v-on:click="GoTo()">
                <img src="~/images/go.bmp" />
            </button>
        </div>
    </div>

    <el-dialog v-model="dialogVisible"
               title="删除"
               width="500"
               :before-close="handleClose">
        <span>确定删除该数据吗?</span>
        <template #footer>
            <div class="dialog-footer">
                <el-button v-on:click="CFFKdelete()" type="danger">删除</el-button>
                <el-button type="primary" v-on:click="close()">
                    取消
                </el-button>
            </div>
        </template>
    </el-dialog>
</div>
<style>
    body {
        background-color: #ffffcc;
    }

    .div {
        width: 410px;
        height: 25px;
        /* background-color: black; */
        margin-left: 400px;
        margin-top: -26px;
        line-height: 25px;
    }

    .span1 {
        font-size: 15px;
    }

    .div button {
        margin: 0 5px;
        background-color: #00000000;
        border: 0px;
    }

    .div a {
        margin: 0 5px;
    }

    a {
        text-decoration: none;
        color: white;
    }

    #pageDiv {
        padding: 10px;
    }

    tbody, td, tfoot, th, thead, tr {
        border-color: inherit;
        background-color: #ffffbb;
        border-style: solid;
        border-width: 0;
    }

    .tableEdit {
        border: solid 1px #B5D6E6;
        border-collapse: collapse;
        width: 99%;
        margin: 5px;
    }

        .tableEdit th {
            text-align: left;
            padding: 5px 8px;
            border: solid 1px #B5D6E6;
            width: 35%;
            background-color: #ffdb6f;
        }

        .tableEdit td {
            width: 65%;
            text-align: left;
            padding: 5px 8px;
            border: solid 1px #B5D6E6;
        }

        .tableEdit thead {
            border: solid 1px #B5D6E6;
            background-color: #C1EBFF;
            padding: 5px;
            font-weight: bold;
        }

            .tableEdit thead tr td {
                font-size: 18px;
                color: #000;
            }
</style>
<script>
    const { createApp, ref, reactive,computed } = Vue
    const { ElMessage } = ElementPlus
    var app = createApp({
        setup() {
            const tableData = ref([])
            const pageCount = ref()//总记录数
            const pageIndex = ref(1)//当前页数
            const pageSize = ref(5)//每页显示数
            const page = computed(() => {
                return Math.ceil(pageCount.value / pageSize.value)
            });//总页数
            const pages = ref()//跳转到的页数
            const form = reactive({
                firstKindId:"",//一级机构编号
                firstKindName:"",//一级机构名称
                firstKindSalaryId:"",//负责人编号
                firstKindSaleId:""//销售负责人编号
            })
            const dialogVisible = ref(false)
            const fskId = ref()

            function fill() {
                axios.get("/CFSK/CFSKSelectFenYe",{
                    params:{
                        currentPage:pageIndex.value,
                        pageSize:pageSize.value
                    }
                }).then(res => {
                    pageCount.value = res.data.rows
                    tableData.value = res.data.list
                }).catch(Error => {
                    console.info(Error)
                })
            }

            fill();

            //首页
            function HomePage() {
            pageIndex.value = 1;
            fill();
        }

            //上一页
            function PreviousPage() {
            if (pageIndex.value != 1) {
                pageIndex.value -= 1;
                fill();
            }
        }

            //下一页
            function NextPage() {
            if (pageIndex.value != page.value) {
                pageIndex.value += 1;
                fill();
            }
        }

            //尾页
            function LastPage() {
            pageIndex.value = page.value;
            fill();
        }


            //转到页数
            function GoTo() {
                if (!isNaN(pages.value)) {
                    if (pages.value > page.value || pages.value < 1) {
                        alert("输入的页数有误！")
                        pages.value = ""
                    } else {
                        pageIndex.value = Number(pages.value)
                        pages.value = ""
                        fill();
                    }
                } else {
                    alert('你输入的不是数字！')
                }
            }

            function add(){
                window.location.href = "/CFSK/CFSKInsert";
            }

            //点击删除按钮弹出删除对话框
            function handleDelete(row){
                fskId.value = row
                dialogVisible.value  = true
            }

            //确定删除按钮
            function CFFKdelete(){
                axios.delete("/CFSK/CFSKDeleteAsync",{
                    params:{
                        FskId:fskId.value
                    }
                }).then(res => {
                    if(res.data == 1){
                        ElMessage({
                            type: 'success',
                            message: '删除成功！'
                        });
                        dialogVisible.value  = false
                        fill();
                    }else{
                        ElMessage({
                            type: 'error',
                            message: '删除失败！'
                        });
                        alert("删除失败！")
                    }
                }).catch(Error => {
                    console.info(Error)
                })
            }

            //关闭删除对话框
            function close(){
                fskId.value = ""
                ElMessage({
                            type: 'info',
                            message: '你已取消删除！'
                        });
                dialogVisible.value  = false
            }

            function handleEdit(id){
                window.location.href = "/CFSK/CFSKUpdate?id="+id;
            }

            return {
                tableData,pageCount,pageIndex,pageSize,page,pages,GoTo,HomePage,LastPage,NextPage,PreviousPage,
                add,form,handleDelete,dialogVisible,CFFKdelete,fskId,close,handleEdit
            }
        }
    })
    app.use(ElementPlus)
    app.mount("#app");
</script>                  